package com.tgy.exception;

import com.tgy.result.GraceJSONResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 自定义异常
 * 目的：统一处理异常信息
 *      便于解耦，service与controller错误的解耦，不会被service返回的类型而限制
 */
public class ResultException extends RuntimeException {

    private GraceJSONResult graceJSONResult;
    private static Logger logger = LoggerFactory.getLogger(ResultException.class);

    public ResultException(GraceJSONResult graceJSONResult) {
        //这儿就是控制台打印的错误信息
        logger.error("异常状态码为：" + graceJSONResult.getStatus()
                + "；具体异常信息为：" + graceJSONResult.getMsg());
        this.graceJSONResult = graceJSONResult;
    }

    public GraceJSONResult getGraceJSONResult() {
        return graceJSONResult;
    }

    public void setGraceJSONResult(GraceJSONResult graceJSONResult) {
        this.graceJSONResult = graceJSONResult;
    }
}
